<template>
  <el-dialog title="就诊信息" :close-on-click-modal="false" :visible.sync="visible" fullscreen center>
    <div class="mod-config" style="padding: 0 15px;">
      <!-- <basic-container style="height: 100%;"> -->
      <div class="custom-info-box">
        <!-- 客户基础信息 -->
        <div class="custom-box">
          <div class="custom-item"><span>姓名：</span><span>{{registerForm.personName}}</span></div>
          <div class="custom-item">
            <span>性别：</span>
            <span v-if="dataForm.gender == 0">男</span>
            <span v-if="dataForm.gender == 1">女</span>
          </div>
          <div class="custom-item"><span>年龄：</span><span>{{registerForm.age}}岁</span></div>
          <div class="custom-item"><span>联系方式：</span><span>{{registerForm.telphone}}</span></div>
          <div class="custom-item"><span>就诊事项：</span><span>{{registerForm.registerConfigName}}</span></div>
          <div class="custom-item"><span>费别：</span><span>{{registerForm.payType==1?'自费':'医保'}}</span></div>
          <div class="custom-item"><span>患者ID：</span><span>{{registerForm.uniqueCode}}</span></div>
          <div style="position: absolute;right: 0;top: 3px;">
            <el-button size="mini" type="primary" icon="el-icon-caret-bottom" @click="openOrClose"></el-button>
          </div>
        </div>
        <!-- 客户详细信息 -->
        <div class="custom-box" v-if="infoVisible">
          <div class="custom-item"><span>{{registerForm.address}}</span></div>
        </div>
      </div>
      <el-tabs class="tabs-info-box" :class="infoVisible?'info-show':''" type="border-card" v-model="activeName"
        @tab-click="tabsChange">
        <el-tab-pane label="预检" name='preCheck' v-if="preCheck">
          <table class="miui-table">
            <tr>
              <td class="miui-table-label">身高</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.height" placeholder="身高"><span slot="append">CM</span></el-input>
              </td>
              <td class="miui-table-label">体重</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.weight" placeholder="体重"><span slot="append">KG</span></el-input>
              </td>
              <td class="miui-table-label">体温</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.temperature" placeholder="体温"><span slot="append">°C</span></el-input>
              </td>
            </tr>
          </table>
          <table class="miui-table">
            <tr>
              <td class="miui-table-label"></td>
              <td class="miui-table-label">裸眼远视力</td>
              <td class="miui-table-label">眼压</td>
              <td class="miui-table-label">旧镜度数</td>
              <td class="miui-table-label">动态屈光检测</td>
            </tr>
            <tr>
              <td class="miui-table-label">右眼</td>
              <td>
                <el-input class="input-width-217" v-model="dataForm.nakedOd"></el-input>
              </td>
              <td>
                <el-input class="input-width-217" v-model="dataForm.iopOd"></el-input>
              </td>
              <td>
                <el-input style="width: 60px;" v-model="dataForm.hisBallOd" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisPostOd" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisAxesOd" placeholder="轴向"></el-input>
              </td>
              <td>
                <el-input style="width: 60px;" v-model="dataForm.mainBallOd" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainPostOd" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainAxesOd" placeholder="轴向"></el-input>
              </td>
            </tr>
            <tr>
              <td class="miui-table-label">左眼</td>
              <td>
                <el-input class="input-width-217" v-model="dataForm.nakedOs"></el-input>
              </td>
              <td>
                <el-input class="input-width-217" v-model="dataForm.iopOs"></el-input>
              </td>
              <td>
                <el-input style="width: 60px;" v-model="dataForm.hisBallOs" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisPostOs" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisAxesOs" placeholder="轴向"></el-input>
              </td>
              <td>
                <el-input style="width: 60px;" v-model="dataForm.mainBallOs" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainPostOs" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainAxesOs" placeholder="轴向"></el-input>
              </td>
            </tr>

          </table>
          <table class="miui-table">
            <tr>
              <td class="miui-table-label">色觉</td>
              <td class="text-left">
                <el-radio-group v-model="dataForm.colorSense">
                  <el-radio :label="1">正常</el-radio>
                  <el-radio :label="2">色弱</el-radio>
                  <el-radio :label="3">色盲</el-radio>
                </el-radio-group>
              </td>
            </tr>
          </table>
        </el-tab-pane>
        <el-tab-pane label="病史" name="history" v-if="!preCheck">
          <el-form label-width="80px">
            <el-form-item label="主诉">
              <el-input type="textarea" v-model="dataForm.chiefComplaint" placeholder="主诉"></el-input>
            </el-form-item>
            <el-form-item label="现病史">
              <el-input type="textarea" v-model="dataForm.hisPresentTalk" placeholder="现病史"></el-input>
            </el-form-item>
            <el-form-item label="既往史">
              <el-checkbox-group v-model="checkList">
                <el-checkbox v-for="(item,index) in bizData.pastHistory" :label="item.label" :key="index"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-row v-if="!checkList.length">
              <h1>无既往史</h1>
            </el-row>
            <el-form-item v-else :label="item" v-for="(item,index) in checkList" :key="index">
              <el-input v-if="item == '疾病史'" type="textarea" v-model="dataForm.diseaseHistory"></el-input>
              <el-input v-if="item == '过敏史'" type="textarea" v-model="dataForm.allergyHistory"></el-input>
              <el-input v-if="item == '手术史'" type="textarea" v-model="dataForm.operationHistory"></el-input>
              <el-input v-if="item == '家族史'" type="textarea" v-model="dataForm.familyHistory"></el-input>
              <el-row v-if="item == '家族史'">
                <el-col :span="8">
                  <el-form-item label="父亲近视史" label-width="120px">
                  <el-select v-model="dataForm.fatherHistory">
                    <el-option v-for="myopiaItem in bizData.myopiaHistory" :value="myopiaItem.value" :label="myopiaItem.label" :key="myopiaItem.value"></el-option>
                  </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="16" v-if="dataForm.fatherHistory && dataForm.fatherHistory != '1'">
                  <el-form-item label="父亲近视史描述" label-width="120px">
                    <el-input type="textarea" v-model="dataForm.fatherHistoryDesc"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row v-if="item == '家族史'">
                <el-col :span="8">
                  <el-form-item label="母亲近视史" label-width="120px">
                  <el-select v-model="dataForm.motherHistory">
                    <el-option v-for="myopiaItem in bizData.myopiaHistory" :value="myopiaItem.value" :label="myopiaItem.label" :key="myopiaItem.value"></el-option>
                  </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="16" v-if="dataForm.motherHistory && dataForm.motherHistory != '1'">
                  <el-form-item label="母亲近视史描述" label-width="120px">
                    <el-input type="textarea" v-model="dataForm.motherHistoryDesc"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-input v-if="item == '其他'" type="textarea" v-model="dataForm.otherHistory"></el-input>
            </el-form-item>


          </el-form>
        </el-tab-pane>
        <el-tab-pane label="体格检查" name="three" v-if="!preCheck">
          <table class="miui-table">
            <tr>
              <td class="miui-table-label">身高</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.height" placeholder="身高"><span slot="append">CM</span></el-input>
              </td>
              <td class="miui-table-label">体重</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.weight" placeholder="体重"><span slot="append">KG</span></el-input>
              </td>
              <td class="miui-table-label">体温</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.temperature" placeholder="体温"><span slot="append">°C</span></el-input>
              </td>
            </tr>
          </table>
          <table class="miui-table">
            <tr>
              <td class="miui-table-label" style="width: 60px;"></td>
              <td class="miui-table-label">眼前段及眼附属器</td>
              <td class="miui-table-label">眼底检查</td>
            </tr>
            <tr>
              <td class="miui-table-label" style="width: 60px;">右眼</td>
              <td style="text-align: left;margin-left: 15px;">
                <el-radio-group v-model="dataForm.frontOd">
                  <el-radio :label="0">正常</el-radio>
                  <el-radio :label="1">异常发现</el-radio>
                </el-radio-group>
                <el-input class="input-width-217" style="margin-left: 15px;" v-if="dataForm.frontOd == 1" v-model="dataForm.frontOdText"></el-input>
              </td>
              <td class="text-left">
                <el-radio-group style="margin-right: 15px;" v-model="dataForm.fundusOd" >
                  <el-radio :label="0">正常</el-radio>
                  <el-radio :label="1">异常发现</el-radio>
                </el-radio-group>
                <el-autocomplete v-if="dataForm.fundusOd == 1" class="inline-input" v-model="dataForm.fundusOdText" :fetch-suggestions="querySearch"></el-autocomplete>
              </td>
            </tr>
            <tr>
              <td class="miui-table-label" style="width: 60px;">左眼</td>
              <td style="text-align: left;margin-left: 15px;">
                <el-radio-group v-model="dataForm.frontOs">
                  <el-radio :label="0">正常</el-radio>
                  <el-radio :label="1">异常发现</el-radio>
                </el-radio-group>
                <el-input class="input-width-217" style="margin-left: 15px;" v-if="dataForm.frontOs == 1" v-model="dataForm.frontOsText"></el-input>
              </td>
              <td class="text-left">
                <el-radio-group style="margin-right: 15px;" v-model="dataForm.fundusOs">
                  <el-radio :label="0">正常</el-radio>
                  <el-radio :label="1">异常发现</el-radio>
                </el-radio-group>
                <el-autocomplete v-if="dataForm.fundusOs == 1" class="inline-input" v-model="dataForm.fundusOsText" :fetch-suggestions="querySearch"></el-autocomplete>
              </td>
            </tr>
          </table>
          <table class="miui-table">
            <tr>
              <td class="miui-table-label">眼位</td>
              <td class="text-left">
                <el-radio-group v-model="dataForm.eyePosition" style="margin-right: 15px">
                  <el-radio label="0">正位</el-radio>
                  <el-radio label="1">隐斜</el-radio>
                  <el-radio label="2">显斜</el-radio>
                </el-radio-group>
                <el-input class="input-width-217" v-if="dataForm.eyePosition == 1" v-model="dataForm.eyePositionText"
                  placeholder="隐斜现象"></el-input>
                <el-input class="input-width-217" v-if="dataForm.eyePosition == 2" v-model="dataForm.eyePositionText"
                  placeholder="显斜现象"></el-input>
              </td>
              <td class="miui-table-label">集合近点(NPC)</td>
              <td class="text-left">
                <el-input class="input-width-217" v-model="dataForm.nearPoint" placeholder="集合近点"><span slot="append">cm</span></el-input>
              </td>
            </tr>
          </table>
        </el-tab-pane>
        <el-tab-pane label="验光" name="optometry" v-if="!preCheck">
          <table class="miui-table">
            <tr>
              <td class="miui-table-label" style="width: 60px;"></td>
              <td class="miui-table-label">裸眼远视力</td>
              <td class="miui-table-label">裸眼近视力</td>
              <td class="miui-table-label">旧镜度数</td>
              <td class="miui-table-label">散瞳验光</td>
              <td class="miui-table-label">矫正视力</td>
              <td class="miui-table-label">主觉验光</td>
              <td class="miui-table-label">Add</td>
            </tr>
            <tr>
              <td class="miui-table-label" style="width: 60px;">右眼</td>
              <td><el-input style="width: 60px;" v-model="dataForm.nakedOd"></el-input></td>
              <td><el-input style="width: 60px;" v-model="dataForm.nakedNearOd"></el-input></td><!-- 裸眼近视力 -->
              <td>
                <el-input style="width: 60px;" v-model="dataForm.hisBallOd" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisPostOd" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisAxesOd" placeholder="轴向"></el-input>
              </td>

              <td>
                <el-input style="width: 60px;" v-model="dataForm.diffuseBallOd" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.diffusePostOd" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.diffuseAxesOd" placeholder="轴向"></el-input>
              </td>
              <td><el-input style="width: 60px;" v-model="dataForm.diffuseCorrectedOd"></el-input></td><!-- 矫正视力 -->
              <td>
                <el-input style="width: 60px;" v-model="dataForm.mainBallOd" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainPostOd" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainAxesOd" placeholder="轴向"></el-input>
              </td>
              <td><el-input style="width: 60px;" v-model="dataForm.addOd"></el-input></td><!-- Add -->
            </tr>
            <tr>
              <td class="miui-table-label" style="width: 60px;">左眼</td>
              <td><el-input style="width: 60px;" v-model="dataForm.nakedOs"></el-input></td>
              <td><el-input style="width: 60px;" v-model="dataForm.nakedNearOs"></el-input></td><!-- 裸眼近视力 -->
              <td>
                <el-input style="width: 60px;" v-model="dataForm.hisBallOs" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisPostOs" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.hisAxesOs" placeholder="轴向"></el-input>
              </td>

              <td>
                <el-input style="width: 60px;" v-model="dataForm.diffuseBallOs" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.diffusePostOs" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.diffuseAxesOs" placeholder="轴向"></el-input>
              </td>
              <td><el-input style="width: 60px;" v-model="dataForm.diffuseCorrectedOs"></el-input></td><!-- 矫正视力 -->
              <td>
                <el-input style="width: 60px;" v-model="dataForm.mainBallOs" placeholder="球镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainPostOs" placeholder="柱镜"></el-input>
                /
                <el-input style="width: 60px;" v-model="dataForm.mainAxesOs" placeholder="轴向"></el-input>
              </td>
              <td><el-input style="width: 60px;" v-model="dataForm.addOs"></el-input></td><!-- Add -->
            </tr>
          </table>
          <table class="miui-table">
            <tr>
              <td class="miui-table-label" style="width: 60px;">优势眼</td>
              <td class="text-left">
                <el-radio-group v-model="dataForm.dominantEye">
                  <el-radio label="Y">右眼</el-radio>
                  <el-radio label="Z">左眼</el-radio>
                </el-radio-group>
              </td>
            </tr>
          </table>
        </el-tab-pane>
        <el-tab-pane label="辅助检查" name="otherCheck" v-if="!preCheck">
          <el-table :data="checkedItems" border style="width: 100%">
            <el-table-column prop="name" label="项目名称" header-align="center" align="center" width="480"></el-table-column>
            <el-table-column prop="num" label="数量" header-align="center" align="center" width="180"></el-table-column>
            <el-table-column prop="price" label="单价" header-align="center" align="center"></el-table-column>
            <el-table-column prop="address" label="操作" header-align="center" align="center">
              <template slot-scope="scope">
                <el-button type="danger" v-if="registerForm.status==4" size="mini" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-table :data="tableData" border style="width: 100%" :show-header="false">
            <el-table-column prop="date" width="480" header-align="center" align="center">
              <template slot-scope="scope">
                <el-select v-model="checkValue" @change="checkItemChange">
                  <el-option v-for="item in itemOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="num" width="180" header-align="center" align="center"></el-table-column>
            <el-table-column prop="address" header-align="center" align="center"></el-table-column>

          </el-table>
          <el-row>
            <el-col :span="24">
              <el-button type="primary" @click="recordCheckResult">录入检查结果</el-button>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="诊断" name="diagnose" v-if="!preCheck">
          <el-form label-width="80px">
            <el-form-item label="门诊诊断">
              <el-input type="textarea" v-model="dataForm.doctorAdvice" placeholder="门诊诊断"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="处方" name="recipel" v-if="!preCheck">
          <el-form>
            <el-row>
              <el-col>
                <el-form-item v-if="registerForm.status==3||registerForm.status==4||registerForm.status==5||registerForm.status==6" label="处方类型">
                  <el-select v-model="recipelVal" @change="recipelChangeHandle" clearable>
                    <el-option v-for="item in bizData.recipelSort" :value="item.value" :label="item.label" :key="item.value"></el-option>
                  </el-select>
                  <el-select v-model="optType">
                    <el-option v-for="item in optTypeOption" :value="item.value" :label="item.label" :key="item.value"></el-option>
                  </el-select>
                  <el-button @click="addNewOptmetry">添加</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <opt-form v-if="registerForm.status==4||registerForm.status==5||registerForm.status==6" :optometry-list="optometryList" :optometry-data="optometry" :optType="optType"
              :source="'register'"></opt-form>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="西医处方" name="xiyi" v-if="!preCheck">
          <outpatient-prescription></outpatient-prescription>
        </el-tab-pane>
        <el-tab-pane label="检查申请" name="check" v-if="!preCheck">
          <check-apply></check-apply>
        </el-tab-pane>
      </el-tabs>

      <div class="button-info-box">
        <el-button @click="visible = false">取 消</el-button>
        <template v-if="registerForm.status==2">
          <el-button type="primary" @click="preSave" v-prevent-re-click>保 存</el-button>
        </template>
        <template v-if="registerForm.status==3">
          <el-button type="primary" @click="updateItemInfo" v-prevent-re-click>保 存</el-button>
        </template>
        <template v-if="registerForm.status==4 || this.registerForm.status==5">
          <el-button type="primary" @click="saveInfo" v-prevent-re-click>保 存</el-button>
          <el-button v-if="registerForm.status==5" type="primary" @click="finish" v-prevent-re-click>结束就诊</el-button>
        </template>
      </div>
      <check-result v-if="resultVisible" ref="checkResult" :data="this.dataForm.checkedItems" :id="this.dataForm.id" :registerForm="registerForm"></check-result>
      <!-- </basic-container> -->
    </div>
  </el-dialog>
</template>
<script>
  import { filterParams } from '@/util/tools'
  import { getSaleOptometry, saveSaleOptometry, updateSaleOptometry, saveInfoOptometry } from '@/api/eims/sale'
  import { getObj, saveChkData, putObj, preSave, updateItemInfo, finishChkData } from '@/api/chkdata/chkdata'
  import { checkItemFetchItem } from '@/api/def/checkItem'
  import { getRegister } from '@/api/eims/cashier/register'
  import { mapGetters } from 'vuex'
  import { remote } from '@/api/admin/dict'
  import CheckResult from './checkresult-form'
  import OptForm from './opt-form'

  // 西医处方
  import OutpatientPrescription from './components/OutpatientPrescription'
  // 检查申请
  import CheckApply from './components/CheckApply'
  export default {
    data() {
      return {
        visible: false,
        infoVisible: false,
        activeName: 'preCheck',
        dataForm: {
          dominantEye: 'Y'
        },
        preCheck: true,
        optometry: {},
        registerForm: {},
        checkList: [],
        restaurants: [],
        recipelVal: '',
        optType: '',
        optTypeOption: [],
        disease: '',
        allergy: '',
        operation: '',
        family: '',
        inspect: '0',
        checkedItems: [],
        fundusOptions: [],
        tableData: [{
          num: '1',
          name: '',
          address: ''
        }],
        checkValue: '',
        itemOptions: [],
        optometryList: [],
        resultVisible: false
      }
    },
    components: {
      CheckResult,
      OptForm,
      OutpatientPrescription,
      CheckApply
    },
    computed: {
      ...mapGetters(['permissions', 'isCollapse', 'bizData'])
    },
    methods: {
      /*
        @ params { type } register -- 预检  chkdata -- 就诊
      */
      init(id, personId, type) {
        this.restaurants = this.bizData.fundusOptions
        this.dataForm.id = id || 0
        this.visible = true
        this.checkList = []
        this.$nextTick(() => {
          //this.$refs['dataForm'].resetFields()
          if (type == 'register') {
            if (this.dataForm.id) {
              this.preCheck = true
              this.activeName = 'preCheck'
              getRegister(this.dataForm.id).then(response => {
                this.registerForm = response.data.data

                this.dataForm.personId = this.registerForm.personId
                this.dataForm.registerId = this.registerForm.id
              })
            }
          } else {
            if (this.dataForm.id) {
              this.preCheck = false
              this.activeName = 'history'
              getObj(this.dataForm.id).then(response => {
                let resultData = response.data.data
                if(resultData.diseaseHistory){
                  this.checkList.push('疾病史')
                }
                if(resultData.allergyHistory){
                  this.checkList.push('过敏史')
                }
                if(resultData.operationHistory){
                  this.checkList.push('手术史')
                }
                if(resultData.familyHistory){
                  this.checkList.push('家族史')
                }
                if(resultData.fatherHistory){
                  this.checkList.push('父亲近视史')
                }
                if(resultData.motherHistory){
                  this.checkList.push('母亲近视史')
                }
                if(resultData.otherHistory){
                  this.checkList.push('其他')
                }
                this.dataForm = resultData
                getRegister(this.dataForm.registerId).then(response => {
                  this.registerForm = response.data.data
                  console.log(this.registerForm)
                  if (this.registerForm.status == 5) {

                  }
                  let params = {
                    dataId: this.dataForm.id,
                    dataTbl: 'chkdata'
                  }
                  getSaleOptometry(params).then(response => {
                    this.optometryList = response.data.data
                  })
                })

                this.checkedItems = this.dataForm.checkedItems
              })
            }
          }
          checkItemFetchItem().then(result => {
            this.itemOptions = result.data.data
          })
        })
        remote('fundus').then(result => {
          this.fundusOptions = result.data.data
        })
      },
      // 打开或关闭客户详情信息
      openOrClose() {
        this.infoVisible = !this.infoVisible
      },
      tabsChange(tab, event) {
        if (tab.name == 'five') {
          // console.log(this.checkList)
        }
      },
      //  检查项目改变
      checkItemChange(val) {
        let obj = {}
        obj = this.itemOptions.find(item => {
          return item.id == val
        })
        let result = this.checkedItems.some(item => {
          if (item.id == obj.id) {
            return true
          }
        })
        if (!result) {
          obj.num = 1
          this.checkedItems.push(obj)
        } else {
          this.$message.warning('该检查项已经添加过了')
        }
        this.checkValue = ''
        console.log(this.dataForm.checkedItems)
      },
      //  删除检查项目
      deleteHandle(id) {
        this.checkedItems.forEach((item, index) => {
          if (item.id == id) {
            this.checkedItems.splice(index, 1)
          }
        })
      },
      preSave() {
        let list = []
        if (!this.registerForm.id) {
          this.$message.warning('请选择就诊数据')
          return false
        }
        preSave(this.dataForm).then(result => {
          if (result.data.code == 0) {
            this.$message.success('保存成功')
            this.visible = false
            this.$emit('refreshDataList')
          }
        })
      },
      updateItemInfo() {
        let list = []
        if (!this.registerForm.id) {
          this.$message.warning('请选择就诊数据')
          return false
        }
        if (this.checkedItems) {
          this.dataForm.checkedItems = this.checkedItems
        }
        updateItemInfo(this.dataForm).then(result => {
          if (result.data.code == 0) {
            this.$message.success('保存成功')
            this.visible = false
            this.$emit('refreshDataList')
          }
        })
      },
      // 结束就诊
      finish() {
        if (!this.registerForm.id) {
          this.$message.warning('请选择就诊数据')
          return false
        }
        // this.optometry.optType = this.optType
        // this.optometry.personId = this.dataForm.personId
        // this.optometry.dataId = this.dataForm.id
        // this.optometry.dataTbl = 'chkdata'
        let params = {
          optometry: this.optometryList,
          chkData: filterParams(this.dataForm)
        }
        saveInfoOptometry(this.optometryList).then(result => {
          if (result.data.code == 0) {}
        })
        finishChkData(params).then(result => {
          if (result.data.code == 0) {
            this.$message.success('保存成功')
            this.visible = false
            this.$emit('refreshDataList')
          }
        })
      },
      // 保存检查数据
      saveInfo() {
        if (!this.registerForm.id) {
          this.$message.warning('请选择就诊数据')
          return false
        }
        let params = {
          optometry: this.optometryList,
          chkData: this.dataForm
        }
        saveInfoOptometry(this.optometryList).then(result => {
          if (result.data.code == 0) {}
        })
        saveChkData(params).then(result => {
          if (result.data.code == 0) {
            this.$message.success('保存成功')
            this.visible = false
            this.$emit('refreshDataList')
          }
        })
      },
      //  录入检查结果
      recordCheckResult() {
        this.resultVisible = true
        this.$nextTick(() => {
          this.$refs.checkResult.init()
        })
      },
      recipelChangeHandle(val){
        this.optType = ''
        this.optTypeOption = []
        let obj = this.bizData.recipelSort.find(item => {
          return item.value == val
        })

        if(obj){
          this.optTypeOption = obj.child
        }
      },
      //  添加处方类型
      addNewOptmetry(){
        if(this.optType){
          let obj = {
            optType: this.optType,
            personId: this.dataForm.personId,
            dataId: this.dataForm.id,
            dataTbl: 'chkdata'
          }
          if(this.optometry.id && this.optometry.id != 0){
            obj.id = this.optometry.id
          }
          this.optometryList.push(obj)
        }
      },
      querySearch(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },

    }
  }
</script>

<style lang="scss" scoped>
  table tr td {
    border: solid 1px red;
    padding: 8px;
  }

  .custom-info-box {
    border: solid 1px #e7e7e7;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
    border-radius: 4px;
    background-color: #d1e0f8;
    margin-bottom: 15px;
  }

  .tabs-info-box {
    z-index: 1000;
  }

  .button-info-box {
    margin-top: 15px;
    text-align: right;
  }

  .custom-box {
    position: relative;
    display: flex;
    justify-content: flex-start;
    padding: 5px 15px;

    .custom-item {
      flex: auto;
    }
  }
  .text-left {
    text-align: left!important;
  }
  .miui-table {
    width: 100%;
    margin: 10px 0;
    background-color: #b1e2ec3b;
    tr th {
      background-color: #f4f5f7;
    }

    tr th, tr td {
      padding: 10px 8px;
      border: solid 1px #fff;
      text-align: center;
    }
    .miui-table-header td{
      background-color: #7898a8;
      color: #fff;
    }
    .miui-table-tbody{
      background-color: #cadee8;
    }
    .miui-table-label {
      max-width: 120px;
      background-color: #b2d5f6;
    }
  }
</style>
